package com.centaline.androidsalesblog.rx.database;

import com.centaline.androidsalesblog.model.databaseobject.CityDo;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

import rx.Observable;
import rx.Subscriber;

/**
 * DB城市列表
 * Created by guilin on 16/2/5.
 */
final class CityListOnSubscribe implements Observable.OnSubscribe<ArrayList<CityDo>> {


    @Override
    public void call(Subscriber<? super ArrayList<CityDo>> subscriber) {
        final List<CityDo> cityDos = DataSupport.findAll(CityDo.class);
        final ArrayList<CityDo> cityDoArrayList = new ArrayList<>();
        for (CityDo cityDo : cityDos) {
            cityDoArrayList.add(cityDo);
        }
        subscriber.onNext(cityDoArrayList);
        subscriber.onCompleted();
    }
}
